package com.bible.test.pad.activity.fragment;

import com.bible.fire.R;
import com.bible.fire.local.CameraManager;
import com.bible.fire.util.SystemConstant;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class NewFragment extends Fragment {
	
	private static final String TAG = NewFragment.class.getSimpleName();
	
	@Override
    public void onCreate(Bundle savedInstanceState){
    	Log.d(TAG, "create titles fragment");
    	super.onCreate(savedInstanceState);
    }
	
	@Override  
    public void onActivityCreated(Bundle savedInstanceState) {  
        super.onActivityCreated(savedInstanceState);  
  
    }  
  
    @Override  
    public void onSaveInstanceState(Bundle outState) {  
        super.onSaveInstanceState(outState);  
    }  
  
    @Override  
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {  
        if (container == null) {              
            return null;  
        }                  
        View view = inflater.inflate(R.layout.activity_camera, container, false);
        Button button = (Button)view.findViewById(R.id.takePicture);
        Button watermarkBtn = (Button)view.findViewById(R.id.btn_watermark);
        button.setOnClickListener( btnListener );
        watermarkBtn.setOnClickListener( btnListener );
        return view;  
    }
    
    private OnClickListener btnListener = new OnClickListener(){
		@Override
		public void onClick(View view) {
			startActivityForResult(CameraManager.takePictures(), SystemConstant.REQUEST_CODE_TAKE_PICTURE );				
		}		
	};
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data){
		super.onActivityResult(requestCode, resultCode, data);
		ImageView imageView = (ImageView)(getView().findViewById(R.id.imageView) );
		CameraManager.actionAfterTake(requestCode, resultCode, data, imageView);
	}

}
